package kosta.controller;

import java.util.HashMap;
import java.util.List;

import javax.annotation.Resource;

import kosta.model.board.BoardVO;
import kosta.model.board.NewsBoardService;
import kosta.model.board.QnABoardService;
import kosta.model.board.TechTipBoardService;
import kosta.model.board.dis.DisBoardService;
import kosta.model.board.dis.DisBoardVO;
import kosta.model.board.file.FileBoardService;
import kosta.model.board.file.FileBoardVO;
import kosta.model.member.MemberService;
import kosta.model.reply.ReplyService;
import kosta.model.reply.dis.DisReplyService;
import kosta.model.reply.dis.DisReplyVO;
import kosta.model.reply.news.NewsReplyService;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class StartController {
	@Resource(name="techTipBoardServiceImpl")
	private TechTipBoardService techTipboardService;
	@Resource(name="disBoardServiceImpl")
	private DisBoardService disBoardService;
	@Resource(name="disReplyServiceImpl")
	private DisReplyService disReplyService;
	@Resource(name="fileBoardServiceImpl")
	private FileBoardService fileBoardService;
	
	//////////news
	@Resource(name="newsBoardServiceImpl")
	private NewsBoardService	 newsBoardService;
	@Resource(name="newsReplyServiceImpl")
	private NewsReplyService newsReplyService;
	
	//// QnA
	@Resource(name="qnABoardServiceImpl")
	private QnABoardService qnABoardService;
	@Resource(name="replyServiceImpl")
	private ReplyService qnaReplyService;
	@Resource(name="memberServiceImpl")
	private MemberService memberService;

	
	@RequestMapping("/ttboard.do")
	public ModelAndView ttboard() throws Exception {
		System.out.println("ttboard");
		List<BoardVO> ttlist=techTipboardService.getListBoard();
		return new ModelAndView("ttBoard/ttboard","ttlist",ttlist);
	}
	
	@RequestMapping("/news.do")
	public String news() {
		System.out.println("news");
		return "news";
	}
	

	
	@RequestMapping("/qnA.do")
	public String qnA() {
		System.out.println("qnA");
		return "qnA";
	}
	
	/**
	 * 토론게시판으로 가기
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/discussion.do")
	public ModelAndView discussion() throws Exception {
		System.out.println("discussion");
		DisBoardVO dvo = disBoardService.disView();
		List<DisReplyVO> list = disReplyService.getDisReplyList(dvo.getDisNo());
		HashMap map = new HashMap();
		map.put("dvo", dvo);
		map.put("list", list);
		return new ModelAndView("/disboard/discussion","map",map);
	}
	
	/**
	 * 다운로드게시판으로 가기
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/download.do")
	public ModelAndView download() throws Exception {
		List<FileBoardVO> list = fileBoardService.getListBoard();
		//System.out.println(list+ " con");
		return new ModelAndView("/fileboard/download","list",list);
	}
	
	@RequestMapping("/home.do")
	public ModelAndView home() throws Exception{
		HashMap map = new HashMap();
		
		BoardVO techVO = techTipboardService.getBoardMain();
		map.put("techVO", techVO);
		
		DisBoardVO disVO = disBoardService.disView();
		map.put("disVO", disVO);
		
		BoardVO newsVO = newsBoardService.getViewBoard();
		map.put("newsVO", newsVO);
		
		BoardVO qnaVO = qnABoardService.findByRand();
		map.put("qnaVO", qnaVO);
		
		System.out.println("map--------" + map);
		return new ModelAndView("index", "map", map);
	}
}
